﻿
<template>
<div class="card-fill layout-padding">
<el-card shadow="hover" class="layout-padding-auto" >
  <WtmSearcher v-model="searchDataBadProductRecord" @search="()=>{getTableDataBadProductRecord();}">
      <el-row>
        <el-col :xs="24" :lg="8" class="mb20">
        <el-form-item ref="FactoryCode_FormItem" prop="FactoryCode" :label="$t('message.autotrans._Model_BadProductRecord_factoryCode')">
            <el-input v-model="searchDataBadProductRecord.FactoryCode" clearable></el-input>
        </el-form-item>

        </el-col>
        <el-col :xs="24" :lg="8" class="mb20">
        <el-form-item ref="LineCode_FormItem" prop="LineCode" :label="$t('message.autotrans._Model_BadProductRecord_lineCode')">
            <el-input v-model="searchDataBadProductRecord.LineCode" clearable></el-input>
        </el-form-item>

        </el-col>
        <el-col :xs="24" :lg="8" class="mb20">
        <el-form-item ref="SnNumber_FormItem" prop="SnNumber" :label="$t('message.autotrans._Model_BadProductRecord_snNumber')">
            <el-input v-model="searchDataBadProductRecord.SnNumber" clearable></el-input>
        </el-form-item>

        </el-col>
        <el-col :xs="24" :lg="8" class="mb20">
        <el-form-item ref="StationCode_FormItem" prop="StationCode" :label="$t('message.autotrans._Model_BadProductRecord_stationCode')">
            <el-input v-model="searchDataBadProductRecord.StationCode" clearable></el-input>
        </el-form-item>

        </el-col>
        <el-col :xs="24" :lg="8" class="mb20">
        <el-form-item ref="MaterialCode_FormItem" prop="MaterialCode" :label="$t('message.autotrans._Model_BadProductRecord_materialCode')">
            <el-input v-model="searchDataBadProductRecord.MaterialCode" clearable></el-input>
        </el-form-item>

        </el-col>
        <el-col :xs="24" :lg="8" class="mb20">
        <el-form-item ref="MaterialName_FormItem" prop="MaterialName" :label="$t('message.autotrans._Model_BadProductRecord_materialName')">
            <el-input v-model="searchDataBadProductRecord.MaterialName" clearable></el-input>
        </el-form-item>

        </el-col>
        <el-col :xs="24" :lg="8" class="mb20">
        <el-form-item ref="MaterialVersion_FormItem" prop="MaterialVersion" :label="$t('message.autotrans._Model_BadProductRecord_materialVersion')">
            <el-input v-model="searchDataBadProductRecord.MaterialVersion" clearable></el-input>
        </el-form-item>

        </el-col>
        <el-col :xs="24" :lg="8" class="mb20">
        <el-form-item ref="OperationCode_FormItem" prop="OperationCode" :label="$t('message.autotrans._Model_BadProductRecord_operationCode')">
            <el-input v-model="searchDataBadProductRecord.OperationCode" clearable></el-input>
        </el-form-item>

        </el-col>
        <el-col :xs="24" :lg="8" class="mb20">
        <el-form-item ref="DefectSource_FormItem" prop="DefectSource" :label="$t('message.autotrans._Model_BadProductRecord_defectSource')">
            <el-input v-model="searchDataBadProductRecord.DefectSource" clearable></el-input>
        </el-form-item>

        </el-col>
        <el-col :xs="24" :lg="8" class="mb20">
        <el-form-item ref="UploadFlag_FormItem" prop="UploadFlag" :label="$t('message.autotrans._Model_BadProductRecord_UploadFlag')">
            <el-select v-model="searchDataBadProductRecord.UploadFlag" clearable>
               <el-option :key="1" :value=true :label="$t('message._system.common.vm.tips_bool_true')"></el-option>
               <el-option :key="0" :value=false :label="$t('message._system.common.vm.tips_bool_false')"></el-option>
            </el-select>
        </el-form-item>

        </el-col>
        <el-col :xs="24" :lg="8" class="mb20">
        <el-form-item ref="CreateTime_FormItem" prop="CreateTime" :label="$t('message.autotrans._Model_BadProductRecord_CreateTime')">
            <el-date-picker v-model="searchDataBadProductRecord.CreateTime" type='daterange' clearable></el-date-picker>
        </el-form-item>

        </el-col>
        <el-col :xs="24" :lg="8" class="mb20">
        <el-form-item ref="UpdateTime_FormItem" prop="UpdateTime" :label="$t('message.autotrans._Model_BadProductRecord_UpdateTime')">
            <el-date-picker v-model="searchDataBadProductRecord.UpdateTime" type='daterange' clearable></el-date-picker>
        </el-form-item>

        </el-col>
        <el-col :xs="24" :lg="8" class="mb20">
        <el-form-item ref="CreateBy_FormItem" prop="CreateBy" :label="$t('message.autotrans._Model_BadProductRecord_CreateBy')">
            <el-input v-model="searchDataBadProductRecord.CreateBy" clearable></el-input>
        </el-form-item>

        </el-col>
        <el-col :xs="24" :lg="8" class="mb20">
        <el-form-item ref="UpdateBy_FormItem" prop="UpdateBy" :label="$t('message.autotrans._Model_BadProductRecord_UpdateBy')">
            <el-input v-model="searchDataBadProductRecord.UpdateBy" clearable></el-input>
        </el-form-item>

        </el-col>
      </el-row>

  </WtmSearcher>

  <div style="text-align: right;">
      <WtmButton v-auth="'/api/Record/BadProductRecord/Create'" icon='fa fa-plus' type='primary' :button-text="$t('message.autotrans.SysCreate')" @click="OnCreateClick()"/>
    <WtmButton v-auth="'/api/Record/BadProductRecord/BatchDelete'"  icon='fa fa-trash' type='danger' :button-text="$t('message.autotrans.SysDelete')" :confirm="$t('message._system.common.vm.deletetip')" @click="onBatchDelete()"/>
    <WtmButton v-auth="'/api/Record/BadProductRecord/BatchEdit'" icon='fa fa-pencil-square' type='primary' :button-text="$t('message.autotrans.SysBatchEdit')" @click="OnBatchEditClick()"/>
    <WtmButton v-auth="'/api/Record/BadProductRecord/Import'" icon='fa fa-tasks' type='primary' :button-text="$t('message.autotrans.SysImport')" @click="OnImportClick()"/>
    <WtmButton v-auth="'/api/Record/BadProductRecord/BadProductRecordExportExcel'"  icon='fa fa-arrow-circle-down' type='primary' :button-text="$t('message.autotrans.SysExport')" @click="onExport()"/>

  </div>
  <WtmTable ref="tableRefBadProductRecord" v-bind="tableDataBadProductRecord">
    <template #operation>
      <el-table-column :label="$t('message._system.common.vm.operate')" width="180">
        <template v-slot="scope">
            <WtmButton v-auth="'/api/Record/BadProductRecord/Edit'" :is-text="true" icon='fa fa-pencil-square' type='warning' :button-text="$t('message.autotrans.SysEdit')" @click="OnEditrowClick(scope.row)"/>
          <WtmButton v-auth="'/api/Record/BadProductRecord/{id}'" :is-text="true" icon='fa fa-info-circle' type='info' :button-text="$t('message.autotrans.Page详情')" @click="OnDetailsrowClick(scope.row)"/>
          <WtmButton v-auth="'/api/Record/BadProductRecord/BatchDelete'"  icon='fa fa-trash' type='danger' :button-text="$t('message.autotrans.SysDelete')" :confirm="$t('message._system.common.vm.deletetip')" :is-text="true"  @click="onDelete(scope.row)"/>

        </template>
      </el-table-column>
    </template>
  </WtmTable>

</el-card>
</div>
</template>


<script setup lang="ts" name="message.autotrans._PageRecordBadProductRecordIndex;true;TyMES.Record.Controllers;BadProductRecord">
import {  ElMessageBox, ElMessage,ElLoading } from 'element-plus';
import { defineAsyncComponent,reactive, ref, getCurrentInstance, onMounted, nextTick } from 'vue';
import { badproductrecordApi } from '/@/api/record/badproductrecord';
import other from '/@/utils/other';
import fileApi from '/@/api/file';
import { useRouter } from "vue-router";
const ci = getCurrentInstance() as any;

const CreateDialog = defineAsyncComponent(() => import('./create.vue'));
const EditDialog = defineAsyncComponent(() => import('./edit.vue'));
const DetailsDialog = defineAsyncComponent(() => import('./details.vue'));
const BatchEditDialog = defineAsyncComponent(() => import('./batchedit.vue'));
const ImportDialog = defineAsyncComponent(() => import('./import.vue'));

const stateBadProductRecord = reactive({
    
});

const searchDataBadProductRecord = ref({
        FactoryCode: '',
        LineCode: '',
        SnNumber: '',
        StationCode: '',
        MaterialCode: '',
        MaterialName: '',
        MaterialVersion: '',
        OperationCode: '',
        DefectSource: '',
        UploadFlag: undefined,
        CreateTime: undefined,
        UpdateTime: undefined,
        CreateBy: '',
        UpdateBy: '',
});

// 定义变量内容
const tableRefBadProductRecord = ref();
const tableDataBadProductRecord = ref({
    // 列表数据（必传）
    data: [],
	// 表头内容（必传，注意格式）
	header: [
      {title:ci.proxy.$t('message.autotrans.Page工厂编码'),key: 'BadProductRecord_factoryCode',type: 'text',isCheck: true},
      {title:ci.proxy.$t('message.autotrans.Page产线编码'),key: 'BadProductRecord_lineCode',type: 'text',isCheck: true},
      {title:ci.proxy.$t('message.autotrans.PageSN号'),key: 'BadProductRecord_snNumber',type: 'text',isCheck: true},
      {title:ci.proxy.$t('message.autotrans.Page工位编号'),key: 'BadProductRecord_stationCode',type: 'text',isCheck: true},
      {title:ci.proxy.$t('message.autotrans.Page物料编码'),key: 'BadProductRecord_materialCode',type: 'text',isCheck: true},
      {title:ci.proxy.$t('message.autotrans.Page物料名称'),key: 'BadProductRecord_materialName',type: 'text',isCheck: true},
      {title:ci.proxy.$t('message.autotrans.Page物料版本'),key: 'BadProductRecord_materialVersion',type: 'text',isCheck: true},
      {title:ci.proxy.$t('message.autotrans.Page工序编码'),key: 'BadProductRecord_operationCode',type: 'text',isCheck: true},
      {title:ci.proxy.$t('message.autotrans.Page不良信息源'),key: 'BadProductRecord_defectSource',type: 'text',isCheck: true},
      {title:ci.proxy.$t('message.autotrans.Page上传标志'),key: 'BadProductRecord_UploadFlag',type: 'switch',isCheck: true},
      {title:ci.proxy.$t('message.autotrans._AdminCreateTime'),key: 'BadProductRecord_CreateTime',type: 'text',isCheck: true},
      {title:ci.proxy.$t('message.autotrans._AdminUpdateTime'),key: 'BadProductRecord_UpdateTime',type: 'text',isCheck: true},
      {title:ci.proxy.$t('message.autotrans._AdminCreateBy'),key: 'BadProductRecord_CreateBy',type: 'text',isCheck: true},
      {title:ci.proxy.$t('message.autotrans._AdminUpdateBy'),key: 'BadProductRecord_UpdateBy',type: 'text',isCheck: true},

	],
	// 配置项（必传）
	config: {
        total: 0, // 列表总数
		loading: true, // loading 加载
		isSerialNo: true, // 是否显示表格序号
		isSelection: true, // 是否显示表格多选
		isOperate: true, // 是否显示表格操作栏
	}
});
// 初始化表格数据
const getTableDataBadProductRecord = () => {
    tableRefBadProductRecord.value.doSearch(badproductrecordApi().search, searchDataBadProductRecord.value)
        .catch((error: any) => {
			other.setFormError(ci, error);
		});
};
const OnCreateClick = () => {
    other.openDialog(ci.proxy.$t('message.autotrans.SysCreate'), CreateDialog, null, getTableDataBadProductRecord)
};

const OnEditrowClick = (row: any) => {
    other.openDialog(ci.proxy.$t('message.autotrans.SysEdit'), EditDialog, row, getTableDataBadProductRecord)
};

const OnDetailsrowClick = (row: any) => {
    other.openDialog(ci.proxy.$t('message.autotrans.Page详情'), DetailsDialog, row, getTableDataBadProductRecord)
};

// 删除
const onDelete = (row: any) => {
    badproductrecordApi().delete([row.ID]).then(() => { getTableDataBadProductRecord()})
};

const onBatchDelete = () => {
    const selectedrows = tableRefBadProductRecord.value.getSelectedRows();
    const selectedids = selectedrows.map((x: any) => x.ID);
    if (selectedids.length > 0)
      badproductrecordApi().delete(selectedids).then(() => { getTableDataBadProductRecord()})
    else
      ElMessage.error(ci.proxy.$t('message._system.common.vm.check'));
};

const OnBatchEditClick = () => {
    const selectedrows = tableRefBadProductRecord.value.getSelectedRows();
    const selectedids = selectedrows.map((x: any) => x.ID);
    if (selectedids.length > 0)
      other.openDialog(ci.proxy.$t('message.autotrans.SysBatchEdit'), BatchEditDialog, selectedids, getTableDataBadProductRecord)
    else
      ElMessage.error(ci.proxy.$t('message._system.common.vm.check'));
};

const OnImportClick = () => {
    other.openDialog(ci.proxy.$t('message.autotrans.SysImport'), ImportDialog, null, getTableDataBadProductRecord)
};

const onExport = () => {
	const selected = tableRefBadProductRecord.value.getSelectedRows();
	if (selected.length > 0) {
		badproductrecordApi().exportById(selected.map((x: any) => x.ID));
	}
	else {
		badproductrecordApi().export({});
	}
};

// 页面加载时
onMounted(() => {
    
        getTableDataBadProductRecord();

});

// 暴露变量
defineExpose({

});
</script>

<style scoped lang="scss">

</style>

